#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
void Swap(int* a, int* b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

int PartSort(int* nums, int start, int end)
{
    int keyi = start;
    while (start < end)
    {
        while(nums[end] >= nums[keyi] && start < end)
        {
            end--;
        }

        while(nums[start] <= nums[keyi] && start < end)
        {
            start++;
        }

        Swap(&nums[end], &nums[start]);
    }

    Swap(&nums[keyi], &nums[start]);
    return start;
}

void QuickSort(int* nums, int start, int end)
{
    if (start >= end)
    {
        return;
    }
    int keyi = PartSort(nums, start, end);
    QuickSort(nums, start, keyi - 1);
    QuickSort(nums, keyi + 1, end);
}

int* sortArray(int* nums, int numsSize, int* returnSize)
{
    QuickSort(nums, 0, numsSize - 1);
    return nums;
}

int main()
{
    int num[4] = { 5, 2, 3, 1 };
    sortArray(num, sizeof(num) / sizeof(num[0]), num);
    int i = 0;
    for(i = 0; i < 4; i++)
    {
        printf("%d", num[i]);
    }
}